package com.mashuai.utils.ztest.toolkit.empty;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.mashuai.utils.base.MsEmptyUtils;
import com.mashuai.utils.toolkit.core.msConverts.MsConvertDataUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: EmptyController
 * @Author : mashuai
 * @Description: TODO
 */
@RestController
@RequestMapping("/empty")
public class EmptyController {

    @GetMapping("/test1")
    public void emptyTest1() {


        List<Map<String, Object>> data = new ArrayList();
        for (int i = 0; i < 3; i++) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("k", i);
            if (i == 1) {
                map.put("kk", "");
            } else {
                map.put("kk", i);
            }
            data.add(map);
        }
        System.err.println(JSON.toJSON(data));
        //处理数据
        for (Map<String, Object> map : data) {
            String kk = MapUtils.getString(map, "kk");
            MsEmptyUtils.isNotEmpty(kk, () -> {
                map.put("kk", IdWorker.get32UUID());
            });
        }
        System.err.println(JSON.toJSON(data));

    }
}
